package com.xpu.stock.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;


@Configuration
public class TaskExecutePoolConfig {
    @Autowired
    private TaskThreadPoolInfo taskThreadPoolInfo;
    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
        //构建线程池对象
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //设置参数
        executor.setCorePoolSize(taskThreadPoolInfo.getCorePoolSize());
        executor.setMaxPoolSize(taskThreadPoolInfo.getMaxPoolSize());
        executor.setKeepAliveSeconds(taskThreadPoolInfo.getKeepAliveSeconds());
        executor.setQueueCapacity(taskThreadPoolInfo.getQueueCapacity());
        //设置线程池任务拒绝策略
        //executor.setRejectedExecutionHandler(null);
        //参数初始化
        executor.initialize();
        return executor;
    }
}
